# -*- coding: utf-8 -*-
# Created by methew at 2018/6/16

"""
error_code type+顺序号
type：
1-网络错误
2-数据库错误
3-资源错误
4-
"""
ErrorTypes = {
    "RequestTypeError": ({"error_code": 1001, "message": 'Request type is error'}, 401),
    "DataBaseTypeError": ({"error_code": 2001, "message": '数据库提交错误'}, 401),
    "DataNoIncludeDataError": ({"error_code": 2001, "message":  "无法查询到具体授权实例"},  401)
}


class Message:

    @staticmethod
    def Msg(errortype=None, message='', data=None, ErrorType=ErrorTypes):
        if errortype is None:
            error_code = 0
            message = message
            data = data
        else:
            ErrorType = ErrorTypes[errortype]
            error_code = ErrorType['error_code']
            message = ErrorType['message']
        if error_code == 0:
            if data is None:
                return {"error_code": 0, "message": message, "data": None}, 201
            else:
                return {"error_code": 0, "message": message, "data": data}, 201
        else:
            return {
                "error_code": ErrorType['error_code'],
                "message": ErrorType['message'],
                "data": data
            }, 401
